package com.gelsanalyzer.application;

import java.util.*;

import org.apache.log4j.*;

import com.gelsanalyzer.business.*;
import com.gelsanalyzer.mvc.controller.*;
import com.gelsanalyzer.mvc.model.*;

/**
 * This class provides the data model necessary to select and add a valid course
 * for the AddCourse Use case in our project.
 * 
 * @author Jared Olhoft
 */
public class CourseSelectorModel extends AbstractModel {
private static final Logger log = Logger.getLogger(CourseSelectorModel.class);

    // Selected Department
    private Department selectedDepartment;
    
    // Departments is a read only list of the currently valid departments.
    private final List<Department> departments;
    private List<Course> courses;

    public CourseSelectorModel() {
        super();
        departments = new DepartmentHome().findAllDepartments();
       
        log.info("Exiting: default constructor");
    }

    /**
     * Method returns a List<Departments> of all departments currently in the
     * Database
     * 
     * @return departments
     */
    public List<Department> getDepartments() {
        log.info("Exiting: getDepartments");
        return departments;
    }
    
    public void setSelectedADepartment( ArrayList<Course> courses ) {
        List<Course> oldCourses = this.courses;;
        log.info("Courses just set. Now calling firePropertyChange...");
        firePropertyChange(
            IController.APP_COURSES_SET, 
            oldCourses, 
            courses);        
    }

    public List<Course> getCourses(Department department) {
        return courses;
    }

    public Department getSelectedDepartment() {
        return selectedDepartment;
    }
    
    public void setSelectedDepartment(Department selectedDepartment) {
        this.selectedDepartment = selectedDepartment;
    }

    @Override
    public void initData() {
        log.info("initData just called...");        
        firePropertyChange(
            IController.APP_DEPARTMENTS_PROPERTY,
            null, departments);
    }

}
